//
//  LLNWConstantManager.m
//  LLFoundation
//
//  Created by my_liu on 2016/11/14.
//  Copyright © 2016年 . All rights reserved.
//

#import "LLNWConstantManager.h"
#import <UIKit/UIKit.h>

@implementation LLNWConstantManager

@synthesize llnwagency;
@synthesize llnwclientTest;
@synthesize llnwcustomId;
@synthesize llnwnewServerURL;
@synthesize llnwserverDomain;
@synthesize llnwversionId;
@synthesize llnwmodel;
@synthesize llnwdataVersion;

+ (instancetype)share
{
    static LLNWConstantManager *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[LLNWConstantManager alloc] init];
    });
    return manager;
}

- (NSString *)llnwmodel
{
    return llnwmodel ? llnwmodel : @"Generic/iphone";
}

- (NSString *)llnwagency
{
    return llnwagency ? llnwagency : @"appstore";
}

- (NSString *)llnwdataVersion
{
    return llnwdataVersion ? llnwdataVersion : @"2.0";
}

- (NSString *)llnwnewServerURL
{
    return llnwnewServerURL ? llnwnewServerURL : @"http://mobds.wanmei.cn/datashare/";
}

- (NSString *)llnwserverDomain
{
    return llnwserverDomain ? llnwserverDomain : @"http://image.wanmeistatic1.com";
}

- (void)isRequireParamNoNull
{
    if (!self.llnwclientTest || !self.llnwcustomId || !self.llnwversionId || !self.llnwclientTest) {
        
        @throw [NSException exceptionWithName:NSInvalidArgumentException reason:@" cucfclientTest， cucfcustomId ，cucfversionId， cucfclientTest 必须赋值" userInfo:nil];
    }
}

- (NSDictionary *)getDefaultHeader
{
    NSMutableDictionary *defaultHeader = [NSMutableDictionary dictionary];
    if (llnwcustomId) {
        [defaultHeader setObject:llnwcustomId forKey:@"customerId"];
    }
    
    [defaultHeader setObject:@"Generic/iphone" forKey:@"model"];
    if (llnwversionId) {
        [defaultHeader setObject:llnwversionId forKey:@"versionId"];
    }
    
    [defaultHeader setObject:@"json2" forKey:@"contentformat"];
    if (llnwagency) {
        [defaultHeader setObject:llnwagency forKey:@"agency"];
    }
    NSString *cleint = [NSString stringWithFormat:@"%@#%0.f*%0.f",[UIDevice currentDevice].model,[UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.width];
    [defaultHeader setObject:cleint forKey:@"clientAgent"];
    return defaultHeader;
}

- (NSDictionary *)getNewApiDefaultHeader
{
    NSMutableDictionary *resultDic = [NSMutableDictionary dictionary];
    if (self.llnwcustomId) {
        [resultDic setObject:self.llnwcustomId forKey:@"X-Wanmei-CustomerId"];
    }
    if (self.llnwversionId) {
        [resultDic setObject:self.llnwversionId forKey:@"X-Wanmei-VersionId"];
    }
    if (self.llnwinstallID) {
        [resultDic setObject:self.llnwinstallID forKey:@"X-Wanmei-InstallId"];
    }
    if (self.llnwagency) {
        [resultDic setObject:self.llnwagency forKey:@"X-Wanmei-Agency"];
    }
    if (self.llnwclientAgent) {
        [resultDic setObject:self.llnwclientAgent forKey:@"X-Wanmei-ClientAgent"];
    }
    if (self.llnwtoken) {
        [resultDic setObject:self.llnwtoken forKey:@"X-Wanmei-token"];
    }
    if (self.llnwcontentType) {
        [resultDic setObject:self.llnwcontentType forKey:@"Content-Type"];
    }
    return resultDic;
}

@end
